package com.uenpay.im.ui.old.activity.movement;

import com.qiyunxin.android.http.utils.StringUtils;
import com.uenpay.im.configuration.APIConfiguration;
import com.uenpay.im.entities.HttpInvokeResult;
import com.uenpay.im.invokeitems.BaseHttpInvokeItem;

import org.json.JSONException;
import org.json.JSONObject;

public class PublishMovementInvokeItem extends BaseHttpInvokeItem {
	public class PublishMovementInvokeItemResult extends HttpInvokeResult {
	}

	public PublishMovementInvokeItemResult getOutput() {
		return (PublishMovementInvokeItemResult) GetResultObject();
	}

	public PublishMovementInvokeItem(int movementid,String title, String starttime,
			String endtime, String personnum, String address, String fee,
			String description, String fileid, String filehash) {
		//http://api.aitiapp.com/Activity/updateActivity?activityid=&title=&starttime=&endtime=&personnum=&address=&fee=&description=
		String url = "";
		if(movementid == 0){
			url = APIConfiguration.getBaseUrl()
				+ "Activity/Activity/addActivity?title=" + StringUtils.encodeParams(title) + "&starttime="
				+ StringUtils.encodeParams(starttime) + "&endtime="
				+ StringUtils.encodeParams(endtime) + "&personnum="
				+ StringUtils.encodeParams(personnum) + "&address="
				+ StringUtils.encodeParams(address) + "&fee=" + StringUtils.encodeParams(fee)
				+ "&description=" + StringUtils.encodeParams(description) + "&fileid="
				+ fileid + "&filehash=" + filehash + "&"
				+ APIConfiguration.getCustIdAndToken();
		}else{
			url = APIConfiguration.getBaseUrl()
					+ "Activity/Activity/updateActivity?activityid="+movementid+"&title=" + StringUtils.encodeParams(title) + "&starttime="
					+ StringUtils.encodeParams(starttime) + "&endtime="
					+ StringUtils.encodeParams(endtime) + "&personnum="
					+ StringUtils.encodeParams(personnum) + "&address="
					+ StringUtils.encodeParams(address) + "&fee=" + StringUtils.encodeParams(fee)
					+ "&description=" + StringUtils.encodeParams(description) + "&fileid="
					+ fileid + "&filehash=" + filehash + "&"
					+ APIConfiguration.getCustIdAndToken();
		}
		SetUrl(url);
	}

	@Override
	protected Object DeserializeResult(String responseBody) {
		PublishMovementInvokeItemResult result = new PublishMovementInvokeItemResult();
		JSONObject json = null;
		try {
			json = new JSONObject(responseBody);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		if (json == null) {
			return null;
		}
		result.status = json.optInt("status");
		result.msg = json.optString("msg");
		if (result.status != 0) {
			return result;
		}
		return result;
	}
}
